import { useUserStore } from '@/store/user'
import { useOrderConfigStore } from '@/store/orderconfig'
import dayjs from 'dayjs'

/** 出库单号前缀 */
const ORDER_PREFIX = 'OUT'

/** 获取新的出库单号 */
export const getNewOutOrderNo = () => {
  const userStore = useUserStore()
  const deviceId = userStore.userInfo.deviceId
  const orderConfigStore = useOrderConfigStore()
  const orderNoInDevice = orderConfigStore.orderConfig.orderNoInDevice
  const timeStr = dayjs().format('YYYYMMDDHHmmss')
  const fields = [ORDER_PREFIX, timeStr]
  /** 单号是否包含设备唯一编码 */
  if (orderNoInDevice) fields.push(deviceId)
  return fields.join('')
}
